import axios from 'axios'
import { NEWS_LIST } from '../constants'

export const getNewsListAc = (payload) => ({
  type: NEWS_LIST,
  payload,
})

export const getNewsList = (id) => {
  return async (dispatch) => {
    const {
      data: {
        data: { results },
      },
    } = await axios.get(
      `http://geek.itheima.net/v1_0/articles?channel_id=${id}&timestamp=${Date.now()}`
    )
    dispatch(getNewsListAc(results))
  }
}
